<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="recMessage">
    Hello World!
  </div>
  <script>
    window.onload = function () {
      var messageEle = document.getElementById('recMessage');
      window.addEventListener('message', function (e) { // 监听 message 事件
        console.log(e);
        // if (e.origin !== "https://www.runoob.com") { // 验证消息来源地址
        //   return;
        // }
        messageEle.innerHTML = "从" + e.origin + "收到消息： " + e.data;
      });
    }
  </script>
</body>

</html>
